package lkj.dao.user.impl;

import lkj.dao.user.UserDao;
import lkj.domain.user.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lkj10 on 2017/3/12.
 */
@Repository
public class UserDaoImpl implements UserDao {
    @Resource
    private SessionFactory sessionFactory;

    protected Session getSession(){
        Session session=sessionFactory.getCurrentSession();
        return session;
    }
    @Override
    public List<User> findAllUser() {
        return getSession().createQuery("from User").list();
    }

    @Override
    public User findId(Integer uid) {
        User user= (User) getSession().createQuery("from User u where u.uid=?")
                .setParameter(0,uid)
                .uniqueResult();
        return user;
    }

    @Override
    public void delete(User user) {
        getSession().delete(user);
    }
}
